/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Martin Zmítko <martin.zmitko@gmail.com>
 */
import cz.uhk.ppro.response.model.Login;
import org.springframework.stereotype.Controller;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import org.springframework.validation.ValidationUtils;

public class LoginValidator implements Validator {

 @Override
  public boolean supports(Class clazz) {
  return Login.class.isAssignableFrom(clazz);
  }
  public void validate(Object obj, Errors errors) {
  Login login = (Login) obj;
  if (login.getUsername() == null || login.getUsername().length() == 0) {
  errors.rejectValue("username",
"error.empty.field", "Please Enter User Name");
  }
  else if (!login.getUsername().equals("admin")) {
  errors.rejectValue("username", "unknown.user", "Unknown User");
  }
  if (login.getPassword() == null || login.getPassword().length() == 0) {
  errors.rejectValue("password",
"error.empty.field", "Please Enter Password");
  }
  else if (!login.getPassword().equals("admin")) {
  errors.rejectValue("password", "wrong.password", "Wrong Password");
  }
  }
}